<template>
	<uni-popup ref="popup">
		<view class="popup-content">
			<image class="bj" :src="bj"></image>
			<view class="content">
				<view class="title alpsoftjurnal">
					{{$t('sign.title2')}}
				</view>
				<view class="cont">
					<view class="text alpsoftjurnal">
						{{$t('signIn.title')}}
						<span>{{qdjl}}</span>
						{{$t('signIn.day')}}
					</view>
					<view class="desc alpsoftjurnal">
						{{$t('signIn.desc')}}
					</view>
					<view class="day alpsoftjurnal">
						<view class="line" :class="item.xz == 2?'select':''" v-for="(item, index) in sign_list "
							:key="index">
							<image class="image" src="@/static/gold.png"></image>
							<view class="num">{{item.discount}}</view>
							<view class="border"></view>
							<view class="date">
								{{ item.day }}
							</view>
						</view>
						<view class="bj2 alpsoftjurnal"></view>
					</view>
					<view class="desc2 ft14 alpsoftjurnal">
						{{$t('signIn.title')}}{{qdjl}}{{$t('signIn.day')}}，{{$t('signIn.text2')}}
						<span v-if="qdjl<7">
							{{sign_rule[qdjl]}}
						</span>
						<span v-else>
							{{sign_rule[0]}}
						</span>
						{{$t('user.gold2')}}
					</view>
					<view class="button alpsoftjurnal" @click="cksigin">{{$t('sign.button')}}+
						<span v-if="qdjl<7">
							{{sign_rule[qdjl]}}
						</span>
						<span v-else>
							{{sign_rule[0]}}
						</span>{{$t('videobuy.text10')}}
					</view>
					<view class="remind">
						<view class="top alpsoftjurnal">
							{{$t('sign.remind')}}
							<switch :checked="SwitchChecked" color="#f75581" style="transform:scale(0.7)" />
						</view>
						<view class="text ft14 alpsoftjurnal">
							{{$t('sign.desc3')}}
						</view>
						<button @click="signFn">签到</button>
					</view>
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		props: {
			sign_list: {},
			sign_rule: {
				type: Array,
				default: () => []
			},
			qdjl: 0,
			tdsy: 0,
		},
		data() {
			return {
				bj: this.$config.staticUrl + 'sigibj.png',
				close: this.$config.staticUrl + 'close.png',
				SwitchChecked: false
			}
		},
		methods: {
			open() {
				this.$refs.popup.open()
				setTimeout(() => {
					console.log('sign_list', this.sign_list);
					console.log('sign_rule', this.sign_rule);
					console.log('qdjl', this.qdjl);
					console.log('tdsy', this.tdsy);
				}, 1000)
			},
			cksigin() {
				let this_ = this
				let data = {};
				data.tdsy = this.tdsy
				data.token = uni.getStorageSync("userinfo").token
				data.uid = uni.getStorageSync("userinfo").id
				data.lang = uni.getStorageSync('language')
				uni.request({
					url: this.configs.webUrl + '/api/user/qingdao',
					data: data,
					success: data => {
						uni.showModal({
							title: this.$t("commmon.text1"),
							content: data.data.msg,
							showCancel: false,
							confirmText: "确定",
							success: res => {
								if (data.data.code == 1) {
									this_.$refs.popup.close()
									this_.$emit('cksigin')
								}
							}
						});
					},
				})
			},
			signFn() {
				let that= this
				uni.getSetting({
					success(res) {
						console.log(res.authSetting)
						if (res.authSetting['scope.subscribeMessage']) {
							// 业务逻辑
						} else {
							uni.requestSubscribeMessage({
								tmplIds: ['ENnUsaSsXhiOVm6HVzEgKdDfsnmfChoRifqpMZ2f2fU'],
								success(res) {
									console.log("订阅成功！", res)
									if(res.ENnUsaSsXhiOVm6HVzEgKdDfsnmfChoRifqpMZ2f2fU == "accept") {
										that.SwitchChecked = true
									} else {
										that.SwitchChecked = false
									}
									// 业务逻辑
								},
								fail(res) {
									// 即使用户拒绝订阅也要继续原来的业务逻辑
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	view {
		font-size: initial;
	}

	.popup-content {
		background: #F75581;
		border-radius: 54rpx;
		position: relative;
		width: 90vw;

		.bj {
			position: absolute;
			top: -390rpx;
			z-index: -1;
			width: 100%;
		}

		.content {
			padding: 10rpx;

			.title {
				font-size: 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				color: #FFF7B9;
				text-align: center;
				padding: 20rpx 0;
			}

			.cont {
				border-radius: 0 0 56rpx 56rpx;
				background: #fff;
				padding: 20rpx 10rpx;

				.text {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #333333;

					span {
						color: #F77623;
					}
				}

				.desc {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #B5B5B5;
					margin: 10rpx 0;
				}

				.day {
					display: flex;
					align-items: center;
					justify-content: space-between;
					position: relative;
					z-index: 10;

					.bj2 {
						position: absolute;
						background: #FFCEDB;
						width: 100%;
						height: 14rpx;
						bottom: 46rpx;
						z-index: -1;
						border-radius: 16rpx;
					}

					.line {
						text-align: center;

						.image {
							width: 56rpx;
							height: 60rpx;
							margin: 0 auto;
						}

						.date,
						.num {
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #333333;
							height: 30rpx;
							margin: 10rpx 0;
						}
						
						.num {
							font-weight: 600;
						}

						.border {
							width: 8rpx;
							height: 8rpx;
							background: #fff;
							border-radius: 50%;
							margin: 0 auto;
						}
					}

					.select {

						.date,
						.num {
							color: #F75581;
						}

						.border {
							background: #F75581;
						}
					}
				}

				.desc2 {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #F75581;
					margin: 20rpx 0 50rpx;
				}

				.button {
					background: linear-gradient(90deg, #F75581 0%, #C860FF 100%);
					border-radius: 48rpx 48rpx 48rpx 48rpx;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #FFFFFF;
					text-align: center;
					padding: 20rpx 0;
					margin: 20rpx 0;
				}

				.remind {
					position: relative;
					button {
						position: absolute;
						top: 0;
						right: 35%;
						width: 100rpx;
						height: 49rpx;
						opacity: 0;
					}
					.top {
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #2F3438;
					}

					.text {
						font-size: 20rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #C1B7B7;
						text-align: center;
					}
				}
			}
		}
	}
</style>